<!--
 * @Author: fengYM feng25321@163.com
 * @Date: 2023-10-07 09:39:50
 * @LastEditors: fengYM feng25321@163.com
 * @LastEditTime: 2023-10-17 14:23:50
 * @Description: 登录
-->
<template>
  <view class="con">
    <view class="inputBox">
      <u-input v-model="formData.cell" placeholder="请输入手机号" border="none"></u-input>
    </view>
    <view class="inputBox">
      <u-input v-model="formData.loginPwd" placeholder="请输入密码" border="none" :password="isPass">
        <template #suffix>
          <view style="display: flex; align-items: center">
            <u-icon name="eye-off" color="#bfbfbf" size="28" v-if="isPass" @click="isPass = false"></u-icon>
            <u-icon name="eye" color="#bfbfbf" size="28" v-else @click="isPass = true"></u-icon>
            <!-- <text class="wjmm" @click="goPage('/pages/login/forgetPassWord')">忘记密码</text> -->
          </view>
        </template>
      </u-input>
    </view>
    <view class="radioBox">
      <u-radio-group>
        <u-radio :customStyle="{ marginTop: '12px' }" label="" name=""> </u-radio>
      </u-radio-group>
      <view class="text">登录即同意<text>《用户协议》</text>和<text>《隐私政策》</text></view>
    </view>
    <u-button type="primary" @click="submit">登录</u-button>
    <view class="register" @click="goPage('/pages/login/register')">立即注册</view>
  </view>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { goPage } from "../../utils/commonFn";
import { getInfo, login } from "../../api/home";
const isPass = ref(true);
const formData = ref({
  cell: "",
  loginPwd: "",
});
const commonFn = (data: any) => {
  return {
    FormId: "BD_CommonContact",
    Data: {
      FieldKeys: "FName,FNumber,FCompany,FCompanyType,FMobile,FBizLocation,FBizLocNumber,F_TEZV_KEY",
      FilterString: data,
      OrderString: "",
      TopRowCount: 0,
      StartRow: 0,
      Limit: 2000,
      SubSystemId: "",
      FormId: "BD_CommonContact",
    },
  };
};
const submit = async () => {
  const res = await getInfo(commonFn([{ Left: "(", FieldName: "FMobile", Compare: "=", Value: formData.value.cell, Right: ")", Logic: "AND" }]));
  if (res.length === 0) {
    uni.showToast({
      title: "请先去注册",
      icon: "none",
    });
    return;
  }
  const res2 = await getInfo(
    commonFn([
      { Left: "(", FieldName: "FMobile", Compare: "=", Value: formData.value.cell, Right: ")", Logic: "AND" },
      { Left: "(", FieldName: "F_TEZV_KEY", Compare: "=", Value: formData.value.loginPwd, Right: ")", Logic: "AND" },
    ])
  );
  if (res2.length === 0) {
    uni.showToast({
      title: "密码错误",
      icon: "none",
    });
    return;
  }
  console.log(res);
  const arr: any[] = [];
  res.forEach((item: string[]) => {
    let obj = {
      FName: item[0],
      FNumber: item[1],
      FCompany: item[2],
      FCompanyType: item[3],
      FMobile: item[4],
      FBizLocation: item[5],
      FBizLocNumber: item[6],
      F_TEZV_KEY: item[7],
    };
    arr.push(obj);
  });
  uni.setStorageSync("userInfo", arr);
  uni.showToast({
    title: "登录成功",
    complete: () => {
      uni.switchTab({
        url: "/pages/home/home",
      });
    },
  });
};
</script>

<style lang="less" scoped>
.con {
  background: #fff;
  height: calc(100vh - 144rpx);
  padding: 120rpx 64rpx 0;
  /deep/ .u-navbar__content__right__text {
    color: #426efe;
  }
  .inputBox {
    padding: 20rpx 0;
    border-bottom: 1rpx solid #f9f9f9;
    .wjmm {
      font-size: 24rpx;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 34rpx;
      margin-left: 15rpx;
    }
  }
  .radioBox {
    display: flex;
    align-items: center;
    margin-top: 40rpx;
    margin-bottom: 120rpx;

    .text {
      margin-top: 10rpx;
      font-size: 24rpx;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #a6a9af;
      line-height: 34rpx;
      text {
        color: #426efe;
      }
    }
  }
  .register {
    text-align: center;
    font-size: 28rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #426efe;
    line-height: 40rpx;
    margin-top: 40rpx;
  }
}
/deep/ .u-radio-group {
  flex: none;
}
</style>
